home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / Tools / Development / PowerD / powerd / source / lib / powerd_lib.lha / PowerD_PPC / EStrAdd.ass < prev    next >
Text File  |  2002-03-24  |  1KB  |  41 lines

  1.  
  2. # EStrAdd(r3:PTR TO ESTRING,r4:PTR TO CHAR,r5=-1:LONG)
  3.  
  4.     .text
  5.     .global    _EStrAdd
  6.  
  7. _EStrAdd:
  8.     and.    r0,r3,r4        # have pointers?
  9.     beq+    .finish
  10.     cmpwi    r5,0
  11.     beq+    .finish
  12.     lhz    r6,-2(r3)        # actual dst length
  13.     lhz    r7,-4(r3)        # maximal dst length
  14.     add    r8,r3,r6        # r8 contains address of the zero byte in dst
  15.     sub    r7,r7,r6
  16.     subi    r7,r7,1        # r7 contains maximal length of the adding string
  17.     cmpwi    r5,0
  18.     bgt+    .skip1
  19.     b    .skip        # the copy size is negative => copy all (means: don't change  r7)
  20. .skip1:    subi    r5,r5,1
  21.     cmpw    r7,r5
  22.     ble+    .skip
  23.     mr    r7,r5        # r7 contains total number of characters to add
  24. .skip:    subi    r8,r8,1        # just to allow the lbzu r8,r8,#1#
  25.     subi    r4,r4,1        # just to allow the lbzu r4,r4,#1#
  26. .loop:    lbzu    r0,1(r4)
  27.     stbu    r0,1(r8)        # add the character
  28.     mr.    r0,r0        # finished?
  29.     beq+    .done
  30.     addi    r6,r6,1        # update the actual dst length
  31.     subi    r7,r7,1        # decrease the add count
  32.     mr.    r7,r7
  33.     bge-    .loop
  34.     li    r0,0
  35.     stb    r0,1(r8)
  36. .done:    sth    r6,-2(r3)
  37. .finish:    blr
  38.  
  39.     .type    _EStrAdd,@function
  40.     .size    _EStrAdd,$-_EStrAdd
  41.